package jackson.src.day04.reflect;

/*
 * Author: JacksonCoder
 * FileName: test
 * Version: 1.0.0
 */
public class test {
    /**
     * 通过Class实例获取class信息的方法称为反射（Reflection）
     */
    public static void main(String[] args) {
        Class cls = String.class;
        System.out.println(cls);
        String s = "hello";
        //
        Class cls2 = s.getClass();
        System.out.println(cls2);
        //
//        Class cls3 = Class.forName("java.lang.Integer");
//        System.out.println(cls3);
        test1();
        System.out.println(demo());

    }

    public static boolean demo(){
        Integer n = new Integer(123);

        boolean b1 = n instanceof Integer; // true，因为n是Integer类型
        boolean b2 = n instanceof Number; // true，因为n是Number类型的子类

        boolean b3 = n.getClass() == Integer.class; // true，因为n.getClass()返回Integer.class
        Class c1 = n.getClass();
        Class c2 = Number.class;
        boolean b4 = c1 == c2; // false，因为Integer.class != Number.class
        return b4;
    }

    public static void test1(){
        Class cls1 = String.class;

        String s = "Hello";
        Class cls2 = s.getClass();

        boolean sameClass = cls1 == cls2; // true
        System.out.println(sameClass);
    }

}
